<script setup>
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const activeBlock = ref();
const selectBlock = (block) => {
  activeBlock.value = block; // 更新选中状态
  router.push(`/${block}`); // 路由跳转
};

onMounted(() => {
  if (router.currentRoute.value.path === '/mrp') {
    selectBlock('mrp');
  }else if (router.currentRoute.value.path === '/debt') {
    selectBlock('debt');
  }

});

</script>

<template>
  <el-container class="layout-container">
    <!-- 头部导航栏 -->
    <el-header class="header">
      <div class="header-left">
        <span class="title">ERP 计算</span>
      </div>
      <div class="header-right">
        <div
          :class="['nav-block', activeBlock === 'mrp' ? 'active' : '']"
          @click="selectBlock('mrp')"
        >
          MRP计算
        </div>
        <div class="divider">|</div>
        <div
          :class="['nav-block', activeBlock === 'debt' ? 'active' : '']"
          @click="selectBlock('debt')"
        >
          负债表计算
        </div>
      </div>
    </el-header>

    <!-- 主内容区域 -->
    <el-main class="content">
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<style scoped>
.layout-container {
  height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 0 20px;
}

.header-left .title {
  font-size: 20px;
  font-weight: bold;
  color: #333333;
}

.header-right {
  display: flex;
  align-items: center;
}

.nav-block {
  padding: 10px 20px;
  cursor: pointer;
  font-size: 16px;
  color: #666666;
  transition: all 0.3s ease;
}

.nav-block.active {
  background-color: #f0f8ff;
  border-radius: 5px;
  color: #409eff;
  transform: scale(0.95); /* 凹陷效果 */
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.divider {
  margin: 0 10px;
  color: #cccccc;
}

.content {
  padding: 20px;
}
</style>